import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardDemo {
    public static final String[] SUITS = {"♦","♥","♠","♣"};

    //生成一副牌
    public static List<Card> buyDeck(){
        List<Card> deck = new ArrayList<>(52);
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card = new Card(j,SUITS[i]);
                deck.add(card);
            }
        }
        return deck;
    }

    //洗牌
    private static void swap(List<Card> deck, int i, int j){
        Card tmp = deck.get(i);
        deck.set(i, deck.get(j));
        deck.set(j,tmp);
    }
    public static void shuffle(List<Card> deck){
        Random random = new Random();
        for (int i = deck.size() - 1; i > 0; i--) {
            int r = random.nextInt(i);
            swap(deck,i,r);
        }
    }

    //发牌
    public static List<List<Card>> play(List<Card> cardList){
        List<Card> hand0 = new ArrayList<>();
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();

        List<List<Card>> ret = new ArrayList<>();
        ret.add(hand0);
        ret.add(hand1);
        ret.add(hand2);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cardList.remove(i);
                ret.get(j).add(card);
            }
        }
        return ret;
    }
}
